
package server.cmd;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import server.dao.TbUserDAO;
import server.vo.TbProcessVO;
import server.vo.TbProjectVO;
import server.vo.TbUserVO;


public class TbUserCmd {
	
	public boolean login(String id, String passwd) {
		if("admin".equals(id) && "1234".equals(passwd)) {
			return true;
		}
		
		return false;
		
		
	}
	
	public boolean logout() {
		return true;
	}
	
	
	/**
	 * getUserListAll TB_USER �귐딅뮞占쏙옙鈺곌퀬��
	 * @param conn
	 * @return String 
	 * @throws Exception 
	 */
	public String getUserListAll(Connection conn) throws Exception {
		
		//FIXME TbUserDAO 占쏙옙占쎄퉫占쏙옙�쇱몵嚥∽옙占쎌쥙堉�占쎌꼷堉깍옙占쏙옙�롪돌 占쎄쑴���얜챷�ｅ첎占쏙옙�됱벉
		TbUserDAO tbUserDAO = new TbUserDAO();
		
		List<TbUserVO> userList = null;
		String szMsg ="";
		
		userList = tbUserDAO.getUserListAll(conn);
		
		for(TbUserVO iter : userList){
			szMsg += iter.getUser_id() + "|" + iter.getUser_name() + "|" + iter.getUser_pwd() + "|" + iter.getLogin_date() + "^";			
		}
		
		return szMsg;
	}

	/**
	 * getUserListByUserName 占쎈�已ワ옙�곗쨮 like TB_USER 鈺곌퀬��
	 * @param conn_thread
	 * @param string
	 * @return
	 */
	public String getUserListByUserName(Connection conn, String param_name) throws Exception {
		//FIXME TbUserDAO 占쏙옙占쎄퉫占쏙옙�쇱몵嚥∽옙占쎌쥙堉�占쎌꼷堉깍옙占쏙옙�롪돌 占쎄쑴���얜챷�ｅ첎占쏙옙�됱벉
		TbUserDAO tbUserDAO = new TbUserDAO();
		
		List<TbUserVO> userList = null;
		String szMsg ="";
		
		TbUserVO tbUserVO = new TbUserVO();
		tbUserVO.setUser_name(param_name);
		
		userList = tbUserDAO.getUserListByUserName(conn, tbUserVO);
		
		for(TbUserVO iter : userList){
			szMsg += iter.getUser_id() + "|" + iter.getUser_name() + "|" + iter.getUser_pwd() + "|" + iter.getLogin_date() + "^";			
		}
		
		return szMsg;
		
	}

	/**
	 * getUserListByUserId ID嚥∽옙TB_USER 鈺곌퀬��
	 * @param conn_thread
	 * @param string
	 * @return
	 * @throws Exception 
	 */
	public String getUserListByUserId(Connection conn, String param_id) throws Exception {
		//FIXME TbUserDAO 占쏙옙占쎄퉫占쏙옙�쇱몵嚥∽옙占쎌쥙堉�占쎌꼷堉깍옙占쏙옙�롪돌 占쎄쑴���얜챷�ｅ첎占쏙옙�됱벉
		TbUserDAO tbUserDAO = new TbUserDAO();
		
		List<TbUserVO> userList = null;
		String szMsg ="";
		
		TbUserVO tbUserVO = new TbUserVO();
		tbUserVO.setUser_id(param_id);
		
		userList = tbUserDAO.getUserListByUserId(conn, tbUserVO);
		
		for(TbUserVO iter : userList){
			szMsg += iter.getUser_id() + "|" + iter.getUser_name() + "|" + iter.getUser_pwd() + "|" + iter.getLogin_date() + "^";			
		}
		
		return szMsg;
	}

	/**
	 * 	 getUserListByPjtCode  pjtCode嚥∽옙占쎈���占쎈슣���닌딄쉐占쏙옙鈺곌퀬��//user_list_by_pjt|50000001-D001
	 * @param conn_thread
	 * @param string
	 * @return
	 * @throws Exception 
	 * @since 2012. 8. 31.
	 */
	public String getUserListByPjtCode(Connection conn_thread, String pjtCode) throws Exception {
		TbUserDAO tbUserDAO = new TbUserDAO();
		
		List<TbUserVO> userList = null;
		String szMsg ="";
		
		
		TbProjectVO tbPjtVO = new TbProjectVO();
		tbPjtVO.setProject_code(pjtCode);
		
		userList = tbUserDAO.getUserListByPjtCode(conn_thread, tbPjtVO);
		
		for(TbUserVO iter : userList){
			szMsg += iter.getUser_id() + "|" + iter.getUser_name() + "|" + iter.getUser_pwd() + "|" + iter.getLogin_date() + "|"+ iter.getRole() +"^";			
		}
		
		return szMsg;
	}

	/**	
	 * registUserToPjt pjtCode占쏙옙userId嚥∽옙pjt占쏙옙user 占쎄퉭以�
	 * @param roll 
	 * @param conn_thread
	 * @param string
	 * @param string2
	 * @return
	 * @throws SQLException 
	 * @since 2012. 8. 31.
	 */
	public String registUserToPjt(Connection conn, String pjtCode, String userId, String roll) throws SQLException {
		
		
		TbProcessVO tbProcessVO = new TbProcessVO();
		
		tbProcessVO.setUesr_id(userId);
		tbProcessVO.setPjt_code(pjtCode);
		tbProcessVO.setRoll(roll);
		TbUserDAO tbUserDAO = new TbUserDAO();
		boolean sucYn = tbUserDAO.registerUserToPjt(conn, tbProcessVO);
		
		String szMsg ="";
		if(sucYn){ // if SUCCESS
			szMsg = "SUCCESS|REGISTER SUCCESS";
		} else {
			szMsg = "FAIL|REGISTER FAIL";
		}
		
		return szMsg;
	}

}
